#include"Func.h"

QNode* BuyQueueNode(QEType x)
{
	QNode* NewNode = (QNode*)malloc(sizeof(QNode));
	assert(NewNode);
	NewNode->data = x;
	NewNode->next = NULL;
	return NewNode;
}

void QueuePush(QNode** Head, QEType x)
{
	assert(Head);
	if (*Head == NULL)
	{
		*Head = BuyQueueNode(x);
		return;
	}
	QNode* tail = *Head;
	while (tail->next)
	{
		tail = tail->next;
	}
	tail->next = BuyQueueNode(x);
}

void QueuePop(QNode** Head)
{
	assert(Head);
	if (*Head == NULL)
	{
		return;
	}
	QNode* NewHead = (*Head)->next;
	free(*Head);
	*Head = NewHead;
}

QEType QueueTop(QNode** Head)
{
	assert(Head);
	return (*Head)->data;
}

bool QueueEmpty(QNode** Head)
{
	return *Head == NULL;
}

void QueueDestroy(QNode** Head)
{
	assert(Head);
	while (*Head)
	{
		QueuePop(Head);
	}
	*Head = NULL;
}